#pragma once
#include "wc3main.h"
#include "wc3refcnt.h"

procedure wc3observer_OnInit();
void wc3observer_main();

	class TEvent : public TRefCnt
	{
	public:
		Dword Id;
		Dword Parameter;
	};

	typedef TEvent* PEvent;
	
	class TObserver : public TRefCnt
	{
	public:
		typedef TObserver* PObserver;
		Pointer Registry;
	public:
		procedure Subscribe(Dword EventId, Dword PassedEventId, PObserver Listener);
		procedure Subscribe(Dword EventId, PObserver Listener);
		procedure Unsubscribe(Dword EventId, PObserver Listener);
		Boolean Notify(TEvent Event);
		Boolean Emit(TEvent Event);
	};
	
	typedef TObserver* PObserver;

	class TObserver_VMT : public TRefCnt_VMT
	{
		typedef procedure (__stdcall *Subscribe_1) (Dword EventId, Dword PassedEventId, const TObserver &Lisneter);
		typedef LongBool (__stdcall *Notify_1) (TEvent Event);
		typedef LongBool (__stdcall *PostEvent_1) (TEvent Event);
		typedef LongBool (__stdcall *PostEventAs_1) (Dword EventId, TEvent Event);
	public:
		Subscribe_1 Subscribe;
		Notify_1 Notify;
		PostEvent_1 PostEvent;
		PostEventAs_1 PostEventAs;
	};

	typedef TObserver_VMT* PObserver_VMT;

	typedef procedure (__stdcall *_CObserver_Unsubscribe_1) (Dword EventId, PObserver Listener);
	//_CObserver_Unsubscribe_1 _CObserver_Unsubscribe;
